package com.xcity.game.player.template;

import java.util.ArrayList;
import java.util.List;

import com.xcity.game.combat.attr.CombatAttribute;
import com.xcity.game.combat.attr.CombatAttributeType;

import naga.x.game.template.Template;
import naga.x.game.template.TemplateException;
import naga.x.game.template.annotation.Excel;

/**
 * 天命（玩家升星）
 * @author yang.li
 *
 */
@Excel(value = "player.xlsx", sheetName = "天命")
public class DestinyTemplate extends Template {

	/** 星级 */
	protected int starLvl;

	/** 名称 */
	protected String name;

	/** 角色等级限制 */
	protected int levelLimit;

	/** 消耗现金 */
	protected int gold;

	/** 消耗副本星数 */
	protected int costStars;

	/** 攻击力提升值 */
	protected float attackPower;

	/** 技能攻击 */
	protected float magicPower;

	/** 生命值 */
	protected float hp;

	/** 防御 */
	protected float defense;

	/** 技能防御 */
	protected float magicDefense;

	/** 暴击 */
	protected float crit;

	/** 韧性 */
	protected float avoidCrit;

	/** 速度 */
	protected float attackSpeed;

	/** 闪避 */
	protected float dodge;

	/** 抵抗 */
	protected float resist;

	/** 普攻命中 */
	protected float hitRate;

	/** 技攻命中 */
	protected float magicHitRate;
	
	protected CombatAttribute[] attributes; // attrs wrapped
	
	public int getLevel() {
		return id;
	}

	public int getStarLvl() {
		return starLvl;
	}

	public void setStarLvl(int starLvl) {
		this.starLvl = starLvl;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getLevelLimit() {
		return levelLimit;
	}

	public void setLevelLimit(int levelLimit) {
		this.levelLimit = levelLimit;
	}

	public int getGold() {
		return gold;
	}

	public void setGold(int gold) {
		this.gold = gold;
	}

	public int getCostStars() {
		return costStars;
	}

	public void setCostStars(int costStars) {
		this.costStars = costStars;
	}

	public float getAttackPower() {
		return attackPower;
	}

	public void setAttackPower(float attackPower) {
		this.attackPower = attackPower;
	}

	public float getMagicPower() {
		return magicPower;
	}

	public void setMagicPower(float magicPower) {
		this.magicPower = magicPower;
	}

	public float getHp() {
		return hp;
	}

	public void setHp(float hp) {
		this.hp = hp;
	}

	public float getDefense() {
		return defense;
	}

	public void setDefense(float defense) {
		this.defense = defense;
	}

	public float getMagicDefense() {
		return magicDefense;
	}

	public void setMagicDefense(float magicDefense) {
		this.magicDefense = magicDefense;
	}

	public float getCrit() {
		return crit;
	}

	public void setCrit(float crit) {
		this.crit = crit;
	}

	public float getAvoidCrit() {
		return avoidCrit;
	}

	public void setAvoidCrit(float avoidCrit) {
		this.avoidCrit = avoidCrit;
	}

	public float getAttackSpeed() {
		return attackSpeed;
	}

	public void setAttackSpeed(float attackSpeed) {
		this.attackSpeed = attackSpeed;
	}

	public float getDodge() {
		return dodge;
	}

	public void setDodge(float dodge) {
		this.dodge = dodge;
	}

	public float getResist() {
		return resist;
	}

	public void setResist(float resist) {
		this.resist = resist;
	}

	public float getHitRate() {
		return hitRate;
	}

	public void setHitRate(float hitRate) {
		this.hitRate = hitRate;
	}

	public float getMagicHitRate() {
		return magicHitRate;
	}

	public void setMagicHitRate(float magicHitRate) {
		this.magicHitRate = magicHitRate;
	}
	
	public float getAttributeValue(CombatAttributeType type) {
		for (CombatAttribute attr : attributes) {
			if (type == attr.getType()) {
				return attr.getValue();
			}
		}
		return 0f;
	}
	
	public CombatAttribute[] getAttributes() {
		return attributes;
	}

	@Override
	public void validate() throws TemplateException {
		// translate attributes
		float[] attrNativeVals = new float[] {
				attackPower, magicPower, defense, magicDefense,
				crit, avoidCrit, hp, attackSpeed,
				0f/*CRIT_DAMAGE*/, 0f/*MP*/, 0f/*MAX_HP*/, 0f/*MAX_MP*/,
				dodge, resist, hitRate, magicHitRate
		};
		List<CombatAttribute> attrs = new ArrayList<CombatAttribute>(5);
		for (int i = 0; i < attrNativeVals.length; i++) {
			if (attrNativeVals[i] > 0f) {
				CombatAttribute wrapped = new CombatAttribute(CombatAttributeType.forType(i), attrNativeVals[i]);
				attrs.add(wrapped);
			}
		}
		attributes = attrs.toArray(new CombatAttribute[attrs.size()]);
	}
}
